package com.cskaoyan.config;

import com.cskaoyan.filter.CustomFilter;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;

/**
 * @author stone
 * @date 2022/11/15 20:59
 */
public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{RootConfiguration.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{WebConfiguration.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

    @Override
    protected Filter[] getServletFilters() {
        CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter();
        //encodingFilter.setForceRequestEncoding(true);
        //encodingFilter.setForceResponseEncoding(true);
        encodingFilter.setForceEncoding(true);
        encodingFilter.setEncoding("utf-8");
        return new Filter[]{new CustomFilter(),encodingFilter};
    }
}
